package cn.itsource.basic.util;

import cn.hutool.core.map.MapUtil;
import cn.hutool.extra.spring.SpringUtil;
import cn.hutool.http.HttpUtil;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;

import java.util.HashMap;
import java.util.Map;


public class SendUtil {
    public static void sendEmail(String subject,String text ,String to ) {
        JavaMailSender javaMailSender = SpringUtil.getBean(JavaMailSender.class);

        SimpleMailMessage mailMessage = new SimpleMailMessage();
        //设置发送人
        mailMessage.setFrom("wangzhihong68@qq.com");
        //邮件主题
        mailMessage.setSubject(subject);
        //邮件内容
        mailMessage.setText(text);
        //收件人
        mailMessage.setTo(to);

        javaMailSender.send(mailMessage);
    }

    /**
     *
     * @param phone 发送的手机号
     * @param smsText 发送的信息
     * @return
     */
    public static String sendSMS(String phone,String smsText) {
        HashMap<String , Object> param = new HashMap<>();
        param.put("Uid", "maizi");
        param.put("Key", "d41d8cd98f00b204e980");
        param.put("smsMob", phone);
        param.put("smsText", smsText);
        Map<String,String > headers = MapUtil.of("Content-Type","application/x-www-form-urlencoded;charset=utf-8");
        return HttpUtil.createPost("https://utf8api.smschinese.cn/").addHeaders(headers).form(param).execute().body();
    }

//    public static void sendEmail(EmailMsg msg) {
//        JavaMailSender javaMailSender = SpringUtil.getBean(JavaMailSender.class);
//
//        SimpleMailMessage mailMessage = new SimpleMailMessage();
//        //设置发送人
//        mailMessage.setFrom("wangzhihong68@qq.com");
//        //邮件主题
//        mailMessage.setSubject(msg.getSubject());
//        //邮件内容
//        mailMessage.setText(msg.getText());
//        //收件人
//        mailMessage.setTo(msg.getTo());
//
//        javaMailSender.send(mailMessage);
//
//    }
}
